const express = require('express')
const cors = require('cors')
const app = express()
const port = 1984
const path = require('path')
app.use(cors())
app.use(express.json())

// 全局中间件
app.use(function (req,res,next) {
    // console.log('全局中间件');
    req.requestTime = Date.now()
    // next()
    res.header('Access-Control-Allow-Origin','*')
    res.header('Access-Control-Allow-Headers','content-type')
    res.header('Access-Control-Allow-Methods','DELETE,PUT,POST,GET,OPTIONS')
    // res.header("Access-Control-Allow-Credentials", true);
    if (req.method == 'OPTIONS') {
        res.sendStatus(200)
    } else {
        next()
    }
})

// app.get('/',(req,res)=>{
//     res.send('hello')
// })

app.use('/message',require('./router/MessageRouter'))
app.use('/musicians',require('./router/MusicianRouter'))
app.use('/statistics',require('./router/ChinaStatisticsRouter'))
app.use('/worldpopulation',require('./router/WorldPopuStatisticsRouter'))
app.use('/jsonmaps',require('./router/MapJSONRouter'))
app.use(express.static(path.join(__dirname,'./public')))

app.listen(port, ()=>{
    console.log('Server running at http://localhost:'+port);
    
})